<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ContextMenu Demo</title>
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="./src/jquery-2.2.4.min.js"></script>
    <link rel="stylesheet" href="./src/contextMenu.css">
    <script src="./src/contextMenu.js"></script>

    <style>
        div.demo{background-color: gray;color: white;margin: 20px;min-width: 200px;min-height:100px;line-height: 100px;font-size: 20px;padding: 1em;border: 3px solid wheat}
        div.btn{cursor: pointer;background-color: brown;color: white;line-height: 30px;display: inline-block;padding: 0.5em;border-radius: 0.5em }
        #div2{height: 1000px;width: 200px}
    </style>
    <script>
        $(function () {
            $('div.btn').click(function () {
                alert($(this).parent().attr('id'));
            });
            $('div.demo').contextmenu(function (e) {
                var menu=[
                    'menu1', //html code
                    'menu2',
                    ['subMenu',
                        [
                            'sub1',
                            'sub2',
                        ]
                    ],
                    '|', //delimiter
                    [
                        'click me', //title
                        function (e) {alert($(e.data).attr('id'))} // onclick
                    ],
                ];
                ContextMenu.render(e,menu,this)
            });
            $('body').contextmenu(function (e) {
                ContextMenu.render(e,true,this)
            });
        })
    </script>

</head>
<body>
<div class="demo" id="div0">
    Hi , I am div0.
    <div class="btn">click me !</div>
    <div class="demo" id="div1">
        Hi , I am div1.
        <div class="btn">click me !</div>
    </div>
</div>
<div class="demo" id="div2">
    Hi , I am div2.
    <div class="btn">click me !</div>
</div>
</body>
</html>